﻿using System;
using System.Collections.Generic;
using System.Text;
using SqlServerDAL;
using System.Data;
using Model;

namespace BLL
{
    public class KilometreBLL
    {
        private readonly KilometreDAL dal = new KilometreDAL();

		#region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Kilometre model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Kilometre model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            return dal.Delete(ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Kilometre GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        ///// <summary>
        ///// 得到一个对象实体，从缓存中
        ///// </summary>
        //public Kilometre GetModelByCache(int ID)
        //{

        //    string CacheKey = "KilometreModel-" + ID;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(ID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch { }
        //    }
        //    return (Kilometre)objModel;
        //}



        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetOrganList(int organID)
        {
            string strWhere = "A.OrganID = " + organID;
            return dal.GetList(strWhere);
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Kilometre> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Kilometre> DataTableToList(DataTable dt)
        {
            List<Kilometre> modelList = new List<Kilometre>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Kilometre model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Kilometre();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["VehicleID"] != null && dt.Rows[n]["VehicleID"].ToString() != "")
                    {
                        model.VehicleID = dt.Rows[n]["VehicleID"].ToString();
                    }
                    if (dt.Rows[n]["FrameNO"] != null && dt.Rows[n]["FrameNO"].ToString() != "")
                    {
                        model.FrameNO = dt.Rows[n]["FrameNO"].ToString();
                    }
                    if (dt.Rows[n]["KM_Time"] != null && dt.Rows[n]["KM_Time"].ToString() != "")
                    {
                        model.KM_Time = DateTime.Parse(dt.Rows[n]["KM_Time"].ToString());
                    }
                    if (dt.Rows[n]["KM_Count"] != null && dt.Rows[n]["KM_Count"].ToString() != "")
                    {
                        model.KM_Count = decimal.Parse(dt.Rows[n]["KM_Count"].ToString());
                    }
                    if (dt.Rows[n]["KM_Image"] != null && dt.Rows[n]["KM_Image"].ToString() != "")
                    {
                        model.KM_Image = (string)dt.Rows[n]["KM_Image"];
                    }
                    if (dt.Rows[n]["OrganID"] != null && dt.Rows[n]["OrganID"].ToString() != "")
                    {
                        model.OrganID = int.Parse(dt.Rows[n]["OrganID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}


		#endregion  Method
    }
}
